angular.module('mall-banner', [])

.controller 'MallBannerCtrl', ($scope, $state, $http, $ionicHistory,showToast, $stateParams, newAddress, wfCache, $ionicViewSwitcher, $ionicPopup,userData,$log,$cordovaCamera,mallInfo) ->
   logger = $log.getInstance 'MallBannerCtrl'
   _.extend $scope,
      banner:
            img:mallInfo.mall.bannerimg
      goBack: ->
          $ionicHistory.goBack()
      goSave: ->
          logger.error 'img'+$scope.banner.img+'  +++ed'
          $http.post('/seller/',{action:'submitbanner',userid:userData.getToken(),banner:$scope.banner.img})
          .success (resp) ->
              if resp?.status == '0'
                  showToast 'banner上传成功!'
              else
                  showToast 'banner上传失败!'
          .error ->
              showToast '您的网络又调皮了!'
      imgAdd: ->
          options =
              quality: 50
              destinationType: Camera.DestinationType.DATA_URL
              sourceType: Camera.PictureSourceType.PHOTOLIBRARY
              allowEdit: true
              encodingType: Camera.EncodingType.JPEG
              popoverOptions: CameraPopoverOptions
              saveToPhotoAlbum: false
          $cordovaCamera.getPicture(options).then ((imageData) ->
              $scope.banner = {img:"data:image/png;base64," + imageData}
          ), (err) -> null